package bishiqiangxun;
import java.util.*;
public class Test1 {
    //题目 : 笔试强训day38 第一题 天使果冻
    //解法一就是 预处理  一下 找出每个范围的第二和最大的数
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        //输入
        int n = in.nextInt();
        int[] arr = new int[n+1];
        for(int i = 1; i <= n; i++) {
            arr[i] = in.nextInt();
        }

        //定义两个数组记录一下  第一和第二大
        int[] dp1 = new int[n+1];
        int[] dp2 = new int[n+1];
        dp1[1] = arr[1];
        for(int i = 2;i <= n; i++) {
            int tmp = arr[i];
            dp1[i] = Math.max(dp1[i-1],tmp);  //哪个大就是哪个
            if(tmp >= dp1[i-1]) {
                dp2[i] = dp1[i-1];
            }else if(tmp >= dp2[i-1]) {
                dp2[i] = tmp;
            }else {
                dp2[i] = dp2[i-1];
            }

        }
        int q = in.nextInt();
        while(q-- > 0) {
            int x = in.nextInt();
            System.out.println(dp2[x]);
        }
    }

    //解法二 : 用优先级队列
    public static void main1(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] numbers = new int[n];
        for(int i = 0;i < n;i++){
            numbers[i] = sc.nextInt();
        }
        int res[] = getSecond(numbers);
        int q = sc.nextInt();
        int[] temp = new int[q];
        for(int i = 0;i < q;i++){
            temp[i] = sc.nextInt();
        }
        for(int t:temp){
            System.out.println(res[t]);
        }
    }

    public static int[] getSecond(int[] numbers){
        int len = numbers.length;
        int[] res = new int[len + 1];
        PriorityQueue<Integer> queue = new PriorityQueue<>();
        queue.add(numbers[0]);
        for(int i = 1;i < len;i++){
            if(queue.size() < 2)queue.add(numbers[i]);
            else {
                if(queue.peek() < numbers[i]){
                    queue.poll();
                    queue.add(numbers[i]);
                }
            }
            res[i + 1] = queue.peek();
        }
        return res;
    }
}
